<template>
    <div class="iosUpload">
      <el-dialog append-to-body  :before-close="cancel" :visible="uploadDialogVisible" width="600px">
        <template slot="title">
            {{title + '文件'}}
        </template>
        <el-form :model="form" ref="form"  label-width="140px">
              <el-upload
                ref="upload"
                drag
                :action="iosUploadApi" 
                class="upload-demo"
                :on-error="uploadError"
                :on-success="uploadSuccess"
                >
               
                <i class="el-icon-upload"></i>
                <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
              </el-upload>

          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="cancel">取 消</el-button>
            <el-button type="primary" @click="handleSubmit">确 定</el-button>
          </div>
      </el-dialog>
    </div>
  </template>
  
  <script>
  // import { getToken } from 'api/qiniu'
  import Cookies from 'js-cookie'
  export default {
    props:{
      title:{
        type : String ,
        default : ''
      },
      fileType:{
        type : String,
        default : ''
      },
      uploadDialogVisible: {
        type : Boolean,
        default : false
      },
      limit :{
        type: Number,
        default : 1
      }
    },
    data(){
      return{
        form :{
          bundleID : undefined,
          download : undefined,
          bookName : undefined,
          plist: undefined,
          ipa : undefined
        },
        iosUploadApi: api.UPLOAD_PIC+'?token='+Cookies.get(consts.CACHE_TOKEN) +'&uid='+Cookies.get(consts.CACHE_UID),
        listObj:{},
        fileList : [],
        
      }
    },
    methods: {
      cancel() {
        this.resetForm('form');
        this.$emit('iosUploadCancel');
        this.$refs.upload.clearFiles();
      },
      // 上传失败
      uploadError(err, file, fileLis){
        // console.log(err, file, fileLis);
        this.$message({
          type : 'warning',
          message: '文件上传失败,请重试'
        });
      },
      // 上传成功
      uploadSuccess(res, file, fileLis){
        // 只取一个上传的文件
        if(fileLis.length > 1){
          fileLis.shift();
        }
        // console.log(fileLis);
      },
      handleSubmit(){

      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    },
  }
  </script>

  <style scoped>

  </style>